package com.example.myapplication11_21;

import androidx.appcompat.app.AppCompatActivity;

        import android.os.Bundle;

import com.github.mikephil.charting.charts.RadarChart;
import com.github.mikephil.charting.data.RadarData;
import com.github.mikephil.charting.data.RadarDataSet;
import com.github.mikephil.charting.data.RadarEntry;
import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        RadarChart chart=findViewById(R.id.chart1);

        float[] f1={25f,36f,82f,55f,48f};
        RadarDataSet d1=getDataSet(f1,"第一组数据");
        float[] f2={15f,26f,72f,45f,38f};
        RadarDataSet d2=getDataSet(f2,"第二组数据");

        List<IRadarDataSet> sets=new ArrayList<>();
        sets.add(d1);
        sets.add(d2);

        RadarData data=new RadarData(sets);
        chart.setData(data);
        chart.invalidate();
    }
    private RadarDataSet getDataSet(float[] data,String title){
        List<RadarEntry> list=new ArrayList<>();
        for (int i=0;i<data.length;i++){
            RadarEntry radarEntry=new RadarEntry(data[i]);
            list.add(radarEntry);
        }
        return new RadarDataSet(list,title);
    }
}

